#!/bin/bash
TEAM_ID=3S5TMAE5S2
TOKEN_KEY_FILE_NAME=/Users/lichongbing/Downloads/lyoggl/src/main/resources/shell/AuthKey_9TPD8SS3C6.p8
AUTH_KEY_ID=9TPD8SS3C6
TOPIC=com.lichongbing.DynamicIsland.IslandPush.push-type.liveactivity
DEVICE_TOKEN=80185599bee03b20338b5549deffc274120c2b5989e2dc963bd90fd1988db97d04dcf8ceedd17135de53596ea6eb1f56e2c8d5281b31ed94bde12a9369ad645d15d1a61cbbe1a7bbd32b961ceeebf57d
APNS_HOST_NAME=api.sandbox.push.apple.com
JWT_ISSUE_TIME=$(date +%s)
JWT_HEADER=$(printf '{ "alg": "ES256", "kid": "%s" }' "${AUTH_KEY_ID}" | openssl base64 -e -A | tr -- '+/' '-_' | tr -d =)
JWT_CLAIMS=$(printf '{ "iss": "%s", "iat": %d }' "${TEAM_ID}" "${JWT_ISSUE_TIME}" | openssl base64 -e -A | tr -- '+/' '-_' | tr -d =)
JWT_HEADER_CLAIMS="${JWT_HEADER}.${JWT_CLAIMS}"
JWT_SIGNED_HEADER_CLAIMS=$(printf "${JWT_HEADER_CLAIMS}" | openssl dgst -binary -sha256 -sign "${TOKEN_KEY_FILE_NAME}" | openssl base64 -e -A | tr -- '+/' '-_' | tr -d =)
AUTHENTICATION_TOKEN="${JWT_HEADER}.${JWT_CLAIMS}.${JWT_SIGNED_HEADER_CLAIMS}"
curl -v --header "apns-topic: $TOPIC" --header "apns-push-type: liveactivity" --header "authorization: bearer $AUTHENTICATION_TOKEN" --data '{
                                                                                                                                          "aps": {
                                                                                                                                              "timestamp": 1168364460,
                                                                                                                                              "event": "update",
                                                                                                                                              "content-state": {
                                                                                                                                                  "driverName": "Anne Johnson",
                                                                                                                                                  "estimatedDeliveryTime": 1659416400
                                                                                                                                              },
                                                                                                                                              "alert": {
                                                                                                                                                  "title": "灵动岛通知",
                                                                                                                                                  "body": "灵动岛通知内容",
                                                                                                                                                  "sound": "example.aiff"
                                                                                                                                              }
                                                                                                                                          }
                                                                                                                                      }' --http2 https://${APNS_HOST_NAME}/3/device/${DEVICE_TOKEN}
